//买卖股票的最佳时机含手续费
class Solution {
public:
    int maxProfit(vector<int>& prices, int fee) {
        int n = prices.size();
        vector<vector<int>> dp(n, vector<int>(2));
        dp[0][0] = -prices[0];
        for (int i = 1; i < n; i++) {
            dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] - prices[i]);
            dp[i][1] = max(dp[i - 1][1], dp[i - 1][0] + prices[i] - fee);
        }
        return dp[n - 1][1];
    }
};

//前缀树
class Trie {
    Trie* hash[26] = {nullptr};
    bool is_have = false;

public:
    Trie() {}

    void insert(string word) {
        int n = word.size();
        Trie* cur = this;
        for (int i = 0; i < word.size(); i++) {
            if (!cur->hash[word[i] - 'a'])
                cur->hash[word[i] - 'a'] = new Trie();
            cur = cur->hash[word[i] - 'a'];
            if (i == n - 1) {
                cur->is_have = true;
            }
        }
    }

    bool search(string word) {
        int n = word.size();
        Trie* cur = this;
        for (int i = 0; i < word.size(); i++) {
            cur = cur->hash[word[i] - 'a'];
            if (!cur)
                return false;
            if (i == n - 1 && cur->is_have == true) {
                return true;
            }
        }
        return false;
    }

    bool startsWith(string word) {
        Trie* cur = this;
        for (int i = 0; i < word.size(); i++) {
            cur = cur->hash[word[i] - 'a'];
            if (!cur)
                return false;
        }
        return true;
    }
};

/**
 * Your Trie object will be instantiated and called as such:
 * Trie* obj = new Trie();
 * obj->insert(word);
 * bool param_2 = obj->search(word);
 * bool param_3 = obj->startsWith(prefix);
 */